#!/usr/bin/env node

const fs = require('fs');
//判断命令行参数是否正确
if(process.argv.length !== 3) {
  console.error('命令行参数格式：cmd file_Name');
  process.exit(1);
}

const width = 16,
      height = 16;
//像素字节
let pixelByte = width * height * 4;
let totalSize = pixelByte + 54; //位图文件头（14字节）+信息头（40字节）

let buf = Buffer.alloc(totalSize); //Buffer.alloc()是创建一个指定大小的Buffer

buf.fill(0);

//data
for(let i=54; i<totalSize; i+=4) {
  buf.writeUInt32LE(0xff0000ff, i);
}

fs.writeFile('./out.bmp', buf, (err) => {
  if(err != null) {
    console.error(err);
    process.exit(1);
  }
});
